package com.wgod.demo.business.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgod.demo.business.entity.AttAchEntity;
import com.wgod.demo.business.mapper.AttAchMapper;
import com.wgod.demo.business.model.AttAchModel;
import com.wgod.demo.common.constant.ErrorConstant;
import com.wgod.demo.common.exception.BusinessException;

import com.wgod.security.common.biz.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 附件服务实现层
 * Created by WGod on 2018/4/29.
 */
@Service
public class AttAchService extends BaseService<AttAchMapper,AttAchEntity> {


    public void addAttAch(AttAchEntity attAchEntity) {
        if (null == attAchEntity)
            throw BusinessException.withErrorCode(ErrorConstant.Common.PARAM_IS_EMPTY);
        mapper.addAttAch(attAchEntity);

    }

    public void batchAddAttAch(List<AttAchEntity> list) {
        if (null == list || list.size() == 0)
            throw BusinessException.withErrorCode(ErrorConstant.Common.PARAM_IS_EMPTY);
        mapper.batchAddAttAch(list);

    }

    public void deleteAttAch(Integer id) {
        if (null == id)
            throw BusinessException.withErrorCode(ErrorConstant.Common.PARAM_IS_EMPTY);
        mapper.deleteAttAch(id);

    }

    public void updateAttAch(AttAchEntity attAchEntity) {
        if (null == attAchEntity || null == attAchEntity.getId())
            throw BusinessException.withErrorCode(ErrorConstant.Common.PARAM_IS_EMPTY);
        mapper.updateAttAch(attAchEntity);

    }

    public AttAchModel getAttAchById(Integer id) {
        if (null == id)
            throw BusinessException.withErrorCode(ErrorConstant.Common.PARAM_IS_EMPTY);
        return mapper.getAttAchById(id);
    }

    public PageInfo<AttAchModel> getAtts(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AttAchModel> atts = mapper.getAtts();
        PageInfo<AttAchModel> pageInfo = new PageInfo<>(atts);
        return pageInfo;
    }

}
